package id;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;


/**
 * Created by Administrator on 2017/12/22.
 */
public class OrderNoLock {

    public static void main(String[] args) {
        
        ExecutorService service =  Executors.newCachedThreadPool();

        final CountDownLatch latch = new CountDownLatch(10);
        for (int i = 0; i <100;i++) {
            service.submit(new Runnable() {
                public void run() {
                    try {
                        //积累10个线程后一起执行getOrder()
                        latch.await();
                        System.out.println(   Thread.currentThread()+getOrder());
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            });
            latch.countDown();
        }
        service.shutdown();
    }
    static AtomicInteger num =new AtomicInteger();
    private static String getOrder() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        return "-----------"+sdf.format(new Date())+"---------"+num.incrementAndGet();
    }
}
